
#include "HAL.h"



void LEDSetPower(uint8_t led,uint8_t lumi,uint8_t pwm)
{
    uint8_t width;
    if (lumi == RGB_LUMI_0)//||(lumi == RGB_LUMI_100))
    {
        PWMX_ACTOUT(pwm, 2, Low_Level, DISABLE);
    }
    else {
        width = LED_WIDTH_MAX / 10 * lumi;
        PWMX_ACTOUT(pwm, width, Low_Level, ENABLE);
    }

}

uint8_t HalLedSet(uint8_t power)
{

    if (power == POWER_OFF)
    {
        PWMX_ACTOUT(LED_R_PWM, 2, Low_Level, DISABLE);
        PWMX_ACTOUT(LED_G_PWM, 2, Low_Level, DISABLE);
        PWMX_ACTOUT(LED_B_PWM, 2, Low_Level, DISABLE);
    }
    else {
        LEDSetPower(HAL_LED_R,LedRGB_Ctrl.LED_R_LUMI,LED_R_PWM);
        LEDSetPower(HAL_LED_G,LedRGB_Ctrl.LED_G_LUMI,LED_G_PWM);
        LEDSetPower(HAL_LED_B,LedRGB_Ctrl.LED_B_LUMI,LED_B_PWM);
    }
   return (0);
}

void HAL_LedInit(void)
{
    /* Initialize all LEDs to OFF */
    GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeOut_PP_5mA); // PA12 - PWM4
    GPIOB_ModeCfg(GPIO_Pin_7, GPIO_ModeOut_PP_5mA); // PA12 - PWM4
    GPIOB_ModeCfg(GPIO_Pin_23, GPIO_ModeOut_PP_5mA); // PA12 - PWM4
    HalLedSet(POWER_OFF);
}


/******************************** endfile @ led ******************************/
